//
//  SwiftUIView_ExtractSubviews.swift
//  SwiftUIPractice
//
//  Created by 5点了啊 (external - Project) on 2024/9/12.
//

import SwiftUI

struct SwiftUIView_ExtractSubviews: View {
    var body: some View {
        
        ZStack {
            
            Color.blue.ignoresSafeArea()
            
            contentLayer
        }
    }
    
    //把子视图 写成一个 属性
    var contentLayer: some View {
        HStack {
            MyItem(title: "苹果", count: 99, color: .red)
            
            MyItem(title: "葡萄", count: 66, color: .purple)
            
            MyItem(title: "橙子", count: 33, color: .orange)
        }
    }
}

/// 把子视图按写成一个单独的 结构体
struct MyItem: View {
    
    let title: String
    let count: Int
    let color: Color
    
    var body: some View {
        
        VStack {
            Text("\(title)")
            Text("\(count)")
        }
        .padding()
        .background(color)
        .cornerRadius(10)
    }
}

#Preview {
    SwiftUIView_ExtractSubviews()
}
